<?php
	class NgoModel extends CI_Model
	{
		public function __construct()
		{
			$this->load->database();
		}
		public final function addNgo($ngo)
		{
			$n = $ngo;
			$a = array
			(
				'Name' => $n->Name,
				'Type' => $n->Type,
				'Description' => $n->Description,
				'Website' => $n->Website,
				'Landline' => $n->Landline,
				'Mobile' => $n->Mobile,
				'Email' => $n->Email,
				'Fax' => $n->Fax,
				'RegistrationNumber' => $n->RegistrationNumber
			);
			return $this->db->insert_id();
		}
		public final function getAllNgos()
		{
			$q = $this->db->get('ngos');
			return $q->result_object();
		}
		public final function getNgoById($id)
		{
			$q = $this->db->get_where('ngos', array('Id' => $id));
			return $q->result_object();
		}
		public final function updateNgo($ngo)
		{
			$n = $ngo;
			$a = array
			(
				'Name' => $n->Name,
				'Type' => $n->Type,
				'Description' => $n->Description,
				'Website' => $n->Website,
				'Landline' => $n->Landline,
				'Mobile' => $n->Mobile,
				'Email' => $n->Email,
				'Fax' => $n->Fax,
				'RegistrationNumber' => $n->RegistrationNumber
			);
			$this->db->where('Id', $n->Id);
			$this->db->update('ngos', $a);
		}
		public final function removeNgoById($id)
		{
			$q = $this->db->delete('ngo', array('Id', $id));
			return $q->result_object();
		}
		public final function acceptDonation()
		{
			$p = $this->input->post;
			$b = $p('beneficiaryId');
			$a = $p('amount');
			$c = $p('companyId');
			$data = array
			(
				'Amount' => $a,
				'BeneficiaryId' => $b,
				'CompanyId' => $c,
				'DateTime' => now()
			);
			$q = $this->db->insert('Donations', $data);
			//PayPal.
		}
	}